// import 'package:amap_flutter_location/amap_flutter_location.dart';
import 'package:flutter/material.dart';
import '../../utils/keepAliveWrapper.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 8, vsync: this);
    _tabController.addListener(() {
      if (_tabController.animation!.value == _tabController.index) {
        print(_tabController.index);
      }
    });
    // AMapFlutterLocation.setApiKey("ef14770dc8b1388639f56b7350cc3bd7", "ios ApiKey");
    // AMapFlutterLocation.updatePrivacyShow(true, true);
    // AMapFlutterLocation.updatePrivacyAgree(true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: PreferredSize(
            preferredSize: const Size.fromHeight(40),
            child: AppBar(
              title: Container(
                height: 35,
                child: TabBar(
                  dividerColor: Colors.transparent,
                  controller: _tabController,
                  labelColor: Colors.white,
                  unselectedLabelColor: Colors.black,
                  indicatorSize: TabBarIndicatorSize.label,
                  isScrollable: true,
                  tabs: const [
                    Tab(text: "Tab 1"),
                    Tab(text: "Tab 2"),
                    Tab(text: "Tab 2"),
                    Tab(text: "Tab 2"),
                    Tab(text: "Tab 2"),
                    Tab(text: "Tab 2"),
                    Tab(text: "Tab 2"),
                    Tab(text: "Tab 2"),
                  ],
                ),
              ),
            )),
        body: TabBarView(
          controller: _tabController,
          children: [
            Container(
                child: KeepAliveWrapper(
              keepAlive: true,
              child: ListView(
                children: const [
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                  ListTile(
                    title: Text("ListTile"),
                  ),
                ],
              ),
            )),
            Container(
              color: Colors.blue,
            ),
            Container(
              color: Colors.green,
            ),
            Container(
              color: Colors.yellow,
            ),
            Container(
              color: Colors.purple,
            ),
            Container(
              color: Colors.purple,
            ),
            Container(
              color: Colors.purple,
            ),
            Container(
              color: Colors.purple,
            )
          ],
        ));
  }
}
